package com.gxa.modules.pc.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Query;
import com.gxa.modules.model.entity.hospital.HospitalPark;
import com.gxa.modules.pc.hospital.mapper.HospitalParkMapper;
import com.gxa.modules.pc.hospital.service.HospitalParkService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 院区表 服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:04:59
 */
@Service
public class HospitalParkServiceImpl extends ServiceImpl<HospitalParkMapper, HospitalPark> implements HospitalParkService {

    @Autowired
    private HospitalParkMapper hospitalParkMapper;

    @Override
    public PageUtils queryByName(Map<String, Object> params) {
        String name = (String) params.get("name");

        IPage<HospitalPark> page = this.page(new Query<HospitalPark>().getPage(params),
                new QueryWrapper<HospitalPark>().likeRight(StringUtils.isNotEmpty(name), "name", name));

        return new PageUtils(page);
    }

    @Override
    public String delByIds(List<Long> ids) {
        QueryWrapper<HospitalPark> wrapper = new QueryWrapper<>();
        wrapper.in("id",ids);
        hospitalParkMapper.delete(wrapper);

        return "删除成功";
    }

    @Override
    public void add(HospitalPark hospitalPark) {
        hospitalParkMapper.insert(hospitalPark);
    }

    @Override
    public void update(HospitalPark hospitalPark) {
        hospitalParkMapper.updateById(hospitalPark);
    }

    @Override
    public HospitalPark queryById(Integer id) {
        return hospitalParkMapper.selectById(id);
    }


}
